<template>
  <div class="background">
    <div class="loginDiv">
      <el-form :model="form" label-width="80px">
        <el-form-item label="用户名">
          <el-input v-model="form.name"></el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input  type="password" v-model="form.password"></el-input>
        </el-form-item>
        <el-row type="flex" justify="center">
          <el-col :span="2">
            <el-button @click="login">登陆</el-button>
          </el-col>
        </el-row>
      </el-form>
    </div>
  </div>
</template>
<script>
import { userList } from "../data/data.js";

export default {
  name: "Login",
  data() {
    return {
      form: {
        name: "",
        password: "",
      },
    };
  },
  methods: {
    login() {
      let that = this;
      console.log(userList);
      let reslut = userList.filter(
        (user) =>
          user.name == that.form.name && user.password == that.form.password
      );
      console.log(reslut);
      if (reslut.length > 0) {
        this.$message({
          showClose: true,
          message: "欢迎"+that.form.name+",回来！！",
          type: "success",
          duration:1000,
        });
        this.$router.push("/home");
      }else{
          this.$message({
          showClose: true,
          message: "用户名或密码错误！！！",
          type: "error",
          duration:1000,
        });
      }
    },
  },
};
</script>
<style scoped>
.background {
  width: 100%;
  height: 100%;
  background-image: url("../assets/bg.jpg");
  background-size: 100% 100%;
}
.loginDiv {
  width: 300px;
  margin: auto;
  position: relative;
  top: 45%;
}
</style> 